<?php
require_once ('ini_set.inc');
require_once ('LyException.php');
require_once ('db.php');
require_once ('ClassUtil.php');
class GenerateObj {
	//protected $fields=array("id","title","content","user_id","weight","type_id","create_time");
	//protected $table_name="content";
	protected $fields;
	protected $table_name;

	public function __construct(){
		$args=func_get_args();
		ClassUtil::callMethodForArgs($this,$args);
	}
	public function construct_(){
	}
	public  function construct_string_string($fields,$table_name){
		$this->fields=$fields;
		$this->table_name=$table_name;
	}
	
	
	protected function db_get_record_by_table_field($talbe_name,$field_name,$value){
		$sql="select * from $talbe_name where $field_name = '$value'";
		echo("<br>".$sql."<br>");
		$result = db_query($sql, "users", "read");
		if (!$result) {
			return 0;
		}
	    return db_get_row($result);
	}
	protected function db_get_obj_by_field($field_name,$value){
		return $this->db_get_record_by_table_field($this->table_name,$field_name,$value);
	}
	
	protected function generate_obj_by_query($query){
		if($query){
			foreach($this->fields as $field){
				$this->$field=$query["$field"];
			}
		}
		else{
			throw new LyException("can't found record from $table_name generate obj fails");
		}
	}
	protected function generate_obj_by_field($field_name,$value){
		$query=$this->db_get_obj_by_field($field_name,$value);
		$this->generate_obj_by_query($query);
	}
	
}
?>